<?php
    //require section
    require_once dirname(__FILE__) . '/shared/config/config.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_multi_level.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_statistics.php';
    $title = 'Danh sách bài tập';

    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'usable_functions.php';
?>

<!DOCTYPE html>
<html>
<head>
    <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php';
    ?>
</head>
<body>
<div class="uk-container uk-container-center uk-margin-top">
    <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php';
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php';

    ?>

    <section id="main-content" class="ts-body-container">
        <div class="ts-left-wrapper">
            <?php
                $cat_id = 0;
                if (!empty($_GET['cat_id'])) {
                    $cat_id   = $_GET['cat_id'];
                    $category = api_document::get_document_category_by_id($cat_id);
                    show_category_group($category, -1);
                } else {
                    ?>
                    <div class="uk-panel uk-margin-bottom">
                        <!--                        <h1 style="color: #fff"><span style='color: cyan; text-decoration: underline;'></span></h1>-->
                        <h3 class="ts-category-title uk-text-center" data-uk-tooltip
                            title="Danh sách <b style='color: #fff'>tất cả bài tập</b>">
                            <i class="uk-icon-folder-open"></i> Tất cả bài tập
                            <span>(<?php echo api_document::count_all_documents(); ?> bài)</span>
                        </h3>
                        <?php
                            $list = api_document::get_all_documents();
                            show_content_group($list);
                        ?>
                    </div>
                <?php
                }
            ?>
            <h1 style="color: #fff"><span style='color: cyan; text-decoration: underline;'></span></h1>

        </div>
        <script type="text/javascript">
            function filldata(value) {
                $.ajax({
                    type: "GET",
                    url: "<?php echo LINK_ROOT . DIR_AJAX; ?>document_folder_category.php",
                    data: "category_choosen_id=" + value,
                    success: function (result) {
                        $("#category-list").html(result);
                    }
                });
            }
            $(document).ready(function () {
                filldata('<?php echo $cat_id; ?>');
            });
        </script>
        <div class="ts-right-wrapper">
            <div class="uk-panel uk-margin-bottom">
                <div class="ts-category-title"><i class="uk-icon-list-ul"></i> Danh mục bài tập</div>
                <ul class="ts-category-list" id="category-list">
                    <!-- ajax loading -->
                    <?php
                        show_root_list();
                    ?>
                </ul>
            </div>

            <div class="uk-panel uk-margin-bottom">
                <div class="ts-category-title"><i class="uk-icon-users"></i> Thống kê truy cập</div>
                <div class="ts-category-content">Tổng số lượt truy cập:
                    <b><?php echo api_statistics::get_access_number(); ?></b></div>
            </div>
        </div>
    </section>

    <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
    ?>
</div>
</body>
</html>